package moonstruckdrops.datastore.provider;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import moonstruckdrops.dao.ProfileDao;
import moonstruckdrops.dto.ProfileDto;

import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class ProfileProvider implements IDataProvider<ProfileDto>,Serializable{
	private static final long serialVersionUID = 1L;

	transient ProfileDao dao;

	public Iterator<? extends ProfileDto> iterator(int first,int count) {
		resolveDao();
		return dao.getProfile(first,count).iterator();
	}
	
	public List<ProfileDto> getProfile(){
		resolveDao();
		return dao.list();
	}

	public int size() {
		resolveDao();
		return dao.ProfleSize();
	}

	public void upDate(String newData,Object key){
		resolveDao();
		dao.upDate(newData, key);
	}
	
	public IModel<ProfileDto> model(ProfileDto object) {
		return new Model<ProfileDto>(object);
	}

	public void detach() {
	}

	void resolveDao() {
		if(dao == null) {
			dao = new ProfileDao();
		}
	}
}
